package t3;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import t3bean.CarBean;
import t3bean.ChargeRecordBean;
import t3bean.ParkingLotBean;
import t3bean.ParkingSpaceBean;

public class Deserialization {
	public ParkingLotBean deserialization() throws NumberFormatException, IOException {
		FileReader fr = new FileReader("D:\\T1\\ParkingLot.txt");
		BufferedReader br = new BufferedReader(fr);
		List<ParkingSpaceBean> spaceList = new ArrayList<ParkingSpaceBean>();
		List<ChargeRecordBean> recordList = new ArrayList<ChargeRecordBean>();
		while (true) {
			CarBean car = new CarBean();
			ParkingSpaceBean ps = new ParkingSpaceBean();
			String id = br.readLine();
			if (id == null || id.equals("") || id.equals(" ")) {
				break;
			}
			ps.setId(Integer.parseInt(id));
			ps.setIsParking(Integer.parseInt(br.readLine()));
			car.setHeight(Integer.parseInt(br.readLine()));
			car.setLicensePlate(br.readLine());
			ps.setCar(car);
			ps.setParkingTime(Long.parseLong(br.readLine()));
			spaceList.add(ps);
		}
		while (true) {
			ChargeRecordBean cr = new ChargeRecordBean();
			String charge = br.readLine();
			if (charge == null) {
				break;
			}
			cr.setCharge(Integer.parseInt(charge));
			cr.setLicensePlate(br.readLine());
			recordList.add(cr);
		}
		ParkingLotBean pl = new ParkingLotBean(spaceList, recordList);
		br.close();
		return pl;
	}
}
